<?php
namespace app\controllers;

use app\models\UpModel;
use Psr\Http\Message\UploadedFileInterface;
use yii\web\UploadedFile;

class UpController extends BaseController{
    //上传
    public function actionAdd(){
        $model = new UpModel();
        if(\Yii::$app->request->isPost){
            $model->image = UploadedFile::getInstance($model,'image');
            $result = $model->up();
        }else{
            $result = ['result'=>0,'data'=>'请从小程序上传'];
        }
        return json_encode($result);
    }

    public function actionDel(){
        $pic = \Yii::$app->request->post('file');
        $pic = empty($pic)?'':str_replace(\Yii::$app->params['pic_url'],'../',$pic);
        @unlink($pic);
        $result = ['result'=>1,'data'=>'操作成功'];
        return json_encode($result);
    }
}
